#!/bin/sh /etc/rc.common
START=80

run_dclient()
{
	local enable
	config_get_bool enable $1 enable
	
	if [ $enable ]; then
		local zteuser
		local ztepass
		local ifname
		local enetuser
		local enetpass
		local timeout
		local dhcpclient
		
		config_get zteuser $1 zteuser
		config_get ztepass $1 ztepass
		config_get ifname $1 ifname
		config_get timeout $1 timeout
		config_get_bool enet $1 enet
		config_get dhcpclient $1 dhcpclient

		if [ -z $timeout ]; then
			timeout='0'
		fi
		
		if [ -z $dhcpclient ] || [ "$dhcpclient" = "auto" ]; then
			dhcpclient=''
		else
			dhcpclient="-i $dhcpclient"
		fi
		
		
		if [ $enet ]; then
			config_get enetuser $1 enetuser
			config_get enetpass $1 enetpass
			echo -e "欢迎使用凌点时代D客户端(中兴802.1X认证)\n微信公众号：凌点时代(DotTimes)\n有问题可以到公众号里面留言哦!\n" >> /tmp/zte.log
			# 这里调用程序  
			dclient -u $zteuser -p $ztepass -d $ifname -t $timeout $dhcpclient -e $enetuser -k $enetpass >/dev/null 2>&1 &
		else
			dclient -u $zteuser -p $ztepass -d $ifname -t $timeout $dhcpclient >/dev/null 2>&1 &
		fi
		
		echo "ZTE Client has started."
	fi
}

start()
{
	# /etc/config/dclient
	config_load /etc/config/dclient
	config_foreach run_dclient login
}

stop()
{
	# 配置停止调用
	local pid=$( ps | grep "dclient -u" | grep -v "grep" | awk '{print $1}' )
	
	if [ -n "$pid" ]; then
		kill -9 $pid
	fi

	echo "ZTE Client has stoped."
}

